import {Component, OnInit, TemplateRef, ViewChild} from '@angular/core';

import {Sider} from './sider';
import {MainService} from './main.service';

@Component({
  selector: 'app-main',
  templateUrl: './main.component.html',
  styleUrls: ['./main.component.css']
})
export class MainComponent implements OnInit {
  public isCollapsed = false;
  public triggerTemplate = null;
  public sider: Sider[] = [];
  public open: Array<boolean> = [];

  @ViewChild('trigger') customTrigger: TemplateRef<void>;

  constructor(private mainService: MainService) {
  }

  private getSider() {
    const siderData = {
      access_token: localStorage.token,
      id: null
    };
    this.mainService.getSider(siderData).subscribe((res: Sider[]) => {
      if (res['status']['errmsg'] === 'success') {
        this.sider = res['data'];
      }
      for (let i = 0, len = this.sider.length; i < len; i++) {
        this.open.push(false);
      }
    });
  }

  ngOnInit() {
    this.getSider();
  }

}
